﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace PacketRush.Core
{
    /// <summary>
    /// Used by <see cref="PacketRush.Core.NetServer"/> and <see cref="PacketRush.Core.NetClient"/> to calculate time based events.
    /// </summary>
    public class NetTimer : NetTime
    {
        private Stopwatch _Timer = new Stopwatch();

        /// <summary>
        /// Starts or resumes the timer.
        /// </summary>
        public void Start()
        {
            _Timer.Start();
        }

        /// <summary>
        /// The total milliseconds elapsed since the timer was started.
        /// </summary>
        public override long ElapsedMilliseconds
        {
            get
            {
                return _Timer.ElapsedMilliseconds;
            }
        }

        /// <summary>
        /// Stops the timer.
        /// </summary>
        public void Stop()
        {
            _Timer.Stop();
        }

        /// <summary>
        /// Stops the timer and resets the elapsed time to zero.
        /// </summary>
        public void Reset()
        {
            _Timer.Reset();
        }

        /// <summary>
        /// Get a value indicating if the timer is currently running.
        /// </summary>
        public bool IsRunning
        {
            get
            {
                return _Timer.IsRunning;
            }
        }
    }
}
